
from loggers.publisher import ZmqPublisher
from loggers.logger import LoggerServer
from config import zmqports
import argparse
import zmq
import time

if __name__ == '__main__':

    parser = argparse.ArgumentParser()
    # parser.add_argument('-p', '--log_path', help='path for log file.',
    #                     action='store_true', default="/tmp")
    args = parser.parse_args()

    ctx = zmq.Context()
    publisher = ZmqPublisher(ctx=ctx, endpoint="tcp://*:" + str(zmqports.LOGGER_PUB_PORT), identity='Logger')
    logger_server = LoggerServer(publisher)

    if not logger_server.load_config():
        print "Fail to initialize loggers"
        exit()

    time.sleep(0.2)
    try:
	    logger_server.start()
	    while True:
    		time.sleep(1)
    finally:
	    logger_server.receiving = False
